summaryrefslogtreecommitdiff
path: root/app/[lng]/evcp/(evcp)/(procurement)/general-contracts/page.tsx
blob: 96f03d091981046270789251ab41014daea275a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { Suspense } from "react"
import { Shell } from "@/components/shell"
import { DataTableSkeleton } from "@/components/data-table/data-table-skeleton"
import {
  getGeneralContracts,
  getGeneralContractStatusCounts,
  getGeneralContractCategoryCounts,
  getVendors
} from "@/lib/general-contracts/service"
import { searchParamsCache } from "@/lib/general-contracts/validation"
import { GeneralContractsTable } from "@/lib/general-contracts/main/general-contracts-table"
import { getValidFilters } from "@/lib/data-table"
import { type SearchParams } from "@/types/table"
import { InformationButton } from "@/components/information/information-button"
import { useTranslation } from "@/i18n"

export const metadata = {
  title: "일반계약 관리",
  description: "일반계약을 생성하고 관리할 수 있습니다.",
}

interface IndexPageProps {
  params: Promise<{ lng: string }>
  searchParams: Promise<SearchParams>
}

export default async function GeneralContractsPage(props: IndexPageProps) {
  const { lng } = await props.params
  const { t } = await useTranslation(lng, 'menu')
  // ✅ searchParams 파싱
  const searchParams = await props.searchParams
  const search = searchParamsCache.parse(searchParams)

  console.log("Parsed search params:", search)

  const validFilters = getValidFilters(search.filters)

  // ✅ 모든 데이터를 병렬로 로드
  const promises = Promise.all([
    getGeneralContracts({
      ...search,
      filters: validFilters,
    }),
    getGeneralContractStatusCounts(),
    getGeneralContractCategoryCounts(),
    getVendors(),
  ])

  return (
    <Shell className="gap-4">
      {/* ═══════════════════════════════════════════════════════════════ */}
      {/* 페이지 헤더 */}
      {/* ═══════════════════════════════════════════════════════════════ */}
      <div className="flex items-center justify-between space-y-2">
        <div className="flex items-center justify-between space-y-2">
          <div>
            <div className="flex items-center gap-2">
              <h2 className="text-2xl font-bold tracking-tight">
                {t('menu.procurement.general_contract')}
              </h2>
              <InformationButton pagePath="evcp/general-contracts" />
            </div>
            <p className="text-muted-foreground">
              {t('menu.procurement.general_contract_desc')}
            </p>
          </div>
        </div>
      </div>

      {/* ═══════════════════════════════════════════════════════════════ */}
      {/* 메인 테이블 */}
      {/* ═══════════════════════════════════════════════════════════════ */}
      <Suspense
        fallback={
          <DataTableSkeleton
            columnCount={15}
            searchableColumnCount={3}
            filterableColumnCount={4}
            cellWidths={["10rem", "8rem", "12rem", "15rem", "10rem", "8rem"]}
            shrinkZero
          />
        }
      >
        <GeneralContractsTable promises={promises} />
      </Suspense>
    </Shell>
  )
}